<template>
  <div class="app-container">
    <div class="search-container">
      <el-form :model="searchParam" :inline="true">
        <el-form-item label="物料号">
          <el-select
            v-model="searchParam.materialId"
            placeholder="请选择物料号"
            filterable
            clearable
          >
            <el-option
              v-for="item in materialOptions"
              :key="item.id"
              :label="`${item.materialCode}-${item.materialName}`"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="操作类型">
          <el-select
            v-model="searchParam.workType"
            placeholder="请选择操作类型"
            filterable
            clearable
          >
            <el-option
              v-for="item in useDictionary('csmRecordType')"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="耗材状态">
          <el-select
            v-model="searchParam.workStatus"
            placeholder="请选择耗材类型"
            filterable
            clearable
          >
            <el-option
              v-for="item in useDictionary('csmStatus')"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="search"
            ><i-ep-search />搜索</el-button
          >
          <el-button @click="reset"><i-ep-refresh />重置</el-button>
        </el-form-item>
      </el-form>
    </div>

    <el-card shadow="never" class="table-container">
      <template #header> </template>

      <el-table
        ref="dataTableRef"
        v-loading="loading"
        :data="tableData"
        highlight-current-row
        border
        @selection-change="handleSelectionChange"
      >
        <el-table-column
          label="物料号"
          prop="materialCode"
          min-width="100"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          label="耗材编码"
          prop="consumeCode"
          min-width="100"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          label="耗材类型"
          prop="materialGroupName"
          min-width="200"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          label="操作类型"
          prop="workType"
          min-width="100"
          show-overflow-tooltip
          align="center"
        >
          <template #default="scope">
            {{
              useDictionary("csmRecordType").find(
                (item) => item.value === scope.row.workType
              )?.label
            }}
          </template>
        </el-table-column>
        <el-table-column
          label="耗材状态"
          prop="workStatus"
          min-width="100"
          show-overflow-tooltip
          align="center"
        >
          <template #default="scope">
            {{
              useDictionary("csmStatus").find(
                (item) => item.value === scope.row.workStatus
              )?.label
            }}
          </template>
        </el-table-column>
        <el-table-column
          label="产生寿命"
          prop="workLife"
          min-width="100"
          show-overflow-tooltip
          align="center"
        >
        </el-table-column>
        <el-table-column
          label="安装时间"
          prop="upTime"
          min-width="100"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          label="拆卸时间"
          prop="downTime"
          min-width="100"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          label="操作人"
          prop="lastUpdatedUserName"
          min-width="100"
          show-overflow-tooltip
          align="center"
        >
        </el-table-column>
      </el-table>

      <el-pagination
        :background="true"
        :current-page="pageable.pageNum"
        :page-size="pageable.pageSize"
        :page-sizes="[10, 25, 50, 100]"
        :total="pageable.total"
        layout="total, sizes, prev, pager, next, jumper"
        class="mt-[20px]"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-card>
  </div>
</template>

<script setup lang="ts">
import { useTable, useDownload, useDictionary } from "@/utils/useTable";
import request from "@/utils/request";
import { useCsmSelectOptionsStore } from "@/views/eam/csm/store/csmSelectOptionsStore";

defineOptions({
  name: "EAMCSMWORKRECORD",
  inheritAttrs: false,
});

const optionsStore = useCsmSelectOptionsStore();
const materialOptions = computed(() => optionsStore.materialOptions);
// 请求参数
const requestApi = "/eam/csmworkrecord/queryByPage";

// 是否需要分页
const pagination = true;

const initParam = {};

// 初始化搜索参数数据
const searchParamInit = {
  materialId: "",
  workType: "",
  workStatus: "",
};

// 数据请求错误后处理
function requestError() {}

const dataCallBack = ref(undefined); // 无需二次数据处理&不传赞数也行

// 表格操作 Hooks
const {
  tableData,
  pageable,
  searchParam,
  ids,
  getTableList,
  search,
  reset,
  handleSizeChange,
  handleCurrentChange,
  handleSelectionChange,
  handleTableDelete,
  loading,
}: any = useTable(
  requestApi,
  initParam,
  searchParamInit,
  pagination,
  dataCallBack.value,
  requestError
);

onMounted(() => {
  getTableList();
  optionsStore.queryMaterialList();
});
</script>
